package com.bysj.sausys.controller.portal;

import com.bysj.sausys.beans.PageQuery;
import com.bysj.sausys.beans.PageResult;
import com.bysj.sausys.common.ActArtConst;
import com.bysj.sausys.common.JsonData;
import com.bysj.sausys.model.SysActArt;
import com.bysj.sausys.service.ISysActArtService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 推文展示Controller
 *
 * @author WangZK
 */
@Api(description = "推文展示接口")
@Controller
@RequestMapping("/actart")
public class ActArtController {

    @Resource
    private ISysActArtService sysActArtService;

    /**
     * 根据推文类型分页获取推文列表
     *
     * @param type
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "根据推文类型分页获取推文列表接口")
    @RequestMapping(value = "/getPageByTypeIsShow", method = RequestMethod.GET)
    @ResponseBody
    public JsonData getPageByTypeIsShow(@ApiParam(value = "推文类别") @RequestParam(required = false) String type,
                                  @ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") int pageNo,
                                  @ApiParam(value = "每页显示条数") @RequestParam(required = false, defaultValue = "10") int pageSize) {
        PageResult result = sysActArtService.getPageByTypeAndShowStatus(type, ActArtConst.SHOW.getCode(), new PageQuery(pageNo, pageSize));
        return JsonData.success(result);
    }

    /**
     * 根据社团id分页获取推文列表
     *
     * @param assId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "根据推文类型分页获取推文列表接口")
    @RequestMapping(value = "/getPageByAssIdIsShow", method = RequestMethod.GET)
    @ResponseBody
    public JsonData getPageByAssIdIsShow(@ApiParam(value = "社团id") @RequestParam(required = false) Integer assId,
                                        @ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") int pageNo,
                                        @ApiParam(value = "每页显示条数") @RequestParam(required = false, defaultValue = "10") int pageSize) {
        PageResult result = sysActArtService.getPageByAssIdAndShowStatus(assId, ActArtConst.SHOW.getCode(), new PageQuery(pageNo, pageSize));
        return JsonData.success(result);
    }


    /**
     * 根据id获取推文内容
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id获取推文内容接口")
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    @ResponseBody
    public JsonData getOne(@ApiParam(value = "推文id", required = true) @RequestParam Integer id) {
        SysActArt sysActArt = sysActArtService.findById(id);
        return JsonData.success(sysActArt);
    }

}
